/**
 * Created by ltx on 2017/9/29.
 */
const express=require('express');
const mysql=require('mysql');

var db=mysql.createPool({host: 'localhost', user: 'root', password: '123456*', database: 'myblog'});

module.exports=function (){
    var router=express.Router();

    router.post('/seenum', (req, res,next)=>{
        //console.log(req.body);
        var articleId=req.body.article_id;

        db.query(`SELECT custompeople FROM newblog_table WHERE ID=${articleId}`,(err,data)=>{
            if (err){
                res.status(500).send('数据库里没有这条数据呐').end();
            }
            else {
                //console.log(data[0].nlike+1);
                db.query(`UPDATE newblog_table SET custompeople='${data[0].custompeople+1}' WHERE ID=${articleId}`,(err,data)=>{
                    if (err){
                        res.status(500).send('数据库里没有这条数据呐0.0').end();
                    }
                    else {
                        console.log('seenum增加成功');
                    }
                })
            }
        })
    });

    return router;
};